package com.hyd.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hyd.common.annotation.Log;
import com.hyd.common.core.controller.BaseController;
import com.hyd.common.core.domain.AjaxResult;
import com.hyd.common.enums.BusinessType;
import com.hyd.manage.domain.Purchase;
import com.hyd.manage.service.IPurchaseService;
import com.hyd.common.utils.poi.ExcelUtil;
    import com.hyd.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 药品采购Controller
 *
 * @author hwb
 * @date 2025-02-19
 */
@Api(tags = "药品采购Controller")
@RestController
@RequestMapping("/manage/purchase")
public class PurchaseController extends BaseController
{
    @Autowired
    private IPurchaseService purchaseService;

/**
 * 查询药品采购列表
 */
@ApiOperation("查询药品采购列表")
@PreAuthorize("@ss.hasPermi('manage:purchase:list')")
@GetMapping("/list")
    public TableDataInfo list(Purchase purchase)
    {
        startPage();
        List<Purchase> list = purchaseService.selectPurchaseList(purchase);
        return getDataTable(list);
    }

    /**
     * 导出药品采购列表
     */
    @ApiOperation("导出药品采购列表")
    @PreAuthorize("@ss.hasPermi('manage:purchase:export')")
    @Log(title = "药品采购", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Purchase purchase)
    {
        List<Purchase> list = purchaseService.selectPurchaseList(purchase);
        ExcelUtil<Purchase> util = new ExcelUtil<Purchase>(Purchase.class);
        util.exportExcel(response, list, "药品采购数据");
    }

    /**
     * 获取药品采购详细信息
     */
    @ApiOperation("获取药品采购详细信息")
    @PreAuthorize("@ss.hasPermi('manage:purchase:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(purchaseService.selectPurchaseById(id));
    }

    /**
     * 新增药品采购
     */
    @ApiOperation("新增药品采购")
    @PreAuthorize("@ss.hasPermi('manage:purchase:add')")
    @Log(title = "药品采购", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Purchase purchase)
    {
        return toAjax(purchaseService.insertPurchase(purchase));
    }

    /**
     * 修改药品采购
     */
    @ApiOperation("修改药品采购")
    @PreAuthorize("@ss.hasPermi('manage:purchase:edit')")
    @Log(title = "药品采购", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Purchase purchase)
    {
        return toAjax(purchaseService.updatePurchase(purchase));
    }

    /**
     * 删除药品采购
     */
    @ApiOperation("删除药品采购")
    @PreAuthorize("@ss.hasPermi('manage:purchase:remove')")
    @Log(title = "药品采购", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(purchaseService.deletePurchaseByIds(ids));
    }
}